import 'package:cms/models/term.dart';
import 'package:common/export/tools.dart';
import 'package:common/utils/lara_press_verify.dart';
import 'package:components/lara_press_box.dart';
import 'package:components/lara_press_img.dart';
import 'package:components/lara_press_text.dart';
import 'package:components/loaders/row_img_loading.dart';
import 'package:flutter/material.dart';

// row img
class LaraPressTermRowImg extends StatelessWidget {
  final WpTerm term;
  final bool isLoading;
  const LaraPressTermRowImg({
    super.key,
    required this.term,
    this.isLoading = false,
  });
  @override
  Widget build(BuildContext context) {
    if (isLoading) {
      return LaraPressBoxConvenience.card(child: LaraPressRowImgLoading());
    }
    return LaraPressBoxConvenience.card(
      borderRadius: 0,
      child: Stack(
        children: [
          Positioned(
            left: 0,
            top: 0,
            bottom: 0,
            child: LaraPressImg(
              img: "${term.cover}",
              width: .3.sw,
              radius: 6.r,
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: .32.sw),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              spacing: 6.h,
              children: [
                LaraPressText(
                  text: "${term.name}",
                  type: LaraPressTextType.listTitle,
                  fontWeight: FontWeight.bold,
                ),
                LaraPressText(
                  text:
                      "${LaraPressVerify.isEmpty(term.description) ? '该分类暂无描述' : term.description}",
                  type: LaraPressTextType.listContent,
                  maxLines: 2,
                  lineHeight: 1.8,
                ),
                Row(
                  children: [
                    LaraPressText(
                      text: "${term.count}篇内容",
                      type: LaraPressTextType.listMeta,
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 带背景的
class LaraPressTermWithBackground extends StatelessWidget {
  final WpTerm term;
  final double width;
  final double height;
  final double radius;
  const LaraPressTermWithBackground({
    super.key,
    required this.term,
    this.width = double.infinity,
    this.height = double.infinity,
    this.radius = 4.0,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(radius)),
      width: width,
      height: height,
      child: Stack(
        alignment: Alignment.bottomLeft,
        children: [
          LaraPressImg(
            img: "${term.cover}",
            width: width,
            height: height,
            radius: radius,
          ),
          Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: ClipRRect(
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(radius),
                bottomRight: Radius.circular(radius),
              ),
              child: LaraPressGlassBox(
                child: Container(
                  color: Colors.transparent,
                  padding: EdgeInsets.symmetric(
                    horizontal: 10.w,
                    vertical: 5.h,
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    spacing: 2.h,
                    children: [
                      LaraPressText(
                        text: "${term.name}",
                        color: Colors.white,
                        type: LaraPressTextType.listContent,
                        maxLines: 1,
                        fontWeight: FontWeight.bold,
                      ),
                      LaraPressText(
                        text: "${term.count}篇内容",
                        color: Colors.white,
                        type: LaraPressTextType.listMeta,
                        maxLines: 1,
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
